package com.egao.common.manage.student;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.student.constants.StudentSignConstants;
import com.egao.common.module.student.entity.StudentSign;
import com.egao.common.module.student.entity.vo.StudentSignListVO;
import com.egao.common.module.student.service.StudentSignService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * 学生毕业去向管理
 * @author lym
 */
@Api(tags = "学生毕业去向管理")
@RestController
@RequestMapping("${api}")
public class StudentSignController extends BaseController {

    @Autowired
    private StudentSignService studentSignService;

    private final String title = "学生毕业去向管理";

    @PreAuthorize("hasAuthority('student')")
    @ApiOperation("分页查询邀约")
    @ApiPageParam
    @GetMapping("/student/sign/page")
    public PageResult<StudentSignListVO> page(HttpServletRequest request) {
        PageParam<StudentSign> pageParam = new PageParam<>(request);
        pageParam.put("company", "0");
        pageParam.put("userId", getLoginUserId());
        return studentSignService.listPage(pageParam);
    }

    @PreAuthorize("hasAuthority('student')")
    @ApiOperation("查询登录学生就业方式 没有则为00")
    @GetMapping("/student/sign/get-sign-category")
    public JsonResult getSignCategory() {
        return studentSignService.getSignCategory(getLoginUserId());
    }

    @PreAuthorize("hasAuthority('student')")
    @OperLog(value = title, desc = "查询详情")
    @ApiOperation("查询详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "邀约主键ID", required = false, dataType = "Integer")
    })
    @GetMapping("/student/sign/detail")
    public JsonResult detail(Integer id) {
        return studentSignService.detail(id, getLoginUserId(), false, getLoginUser().getUserType());
    }

    @PreAuthorize("hasAuthority('student')")
    @OperLog(value = title, desc = "选择就业方式", result = true)
    @ApiOperation(value = "选择就业方式")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "StudentIntenVO", value = "StudentIntenVO", required = true, dataType = "StudentIntenVO")
    })
    @PutMapping("/student/sign/pick-sign-category")
    public JsonResult pickSignCategory(String signCategory) {
        return studentSignService.pickSignCategory(signCategory, getLoginUserId());
    }

    @PreAuthorize("hasAuthority('student')")
    @OperLog(value = title, desc = "重置就业方式", result = true)
    @ApiOperation(value = "重置就业方式")
    @PutMapping("/student/sign/reset-sign-category")
    public JsonResult resetSignCategory() {
        return studentSignService.resetSignCategory(getLoginUserId());
    }

    @PreAuthorize("hasAuthority('student')")
    @OperLog(value = title, desc = "选择录用方式")
    @ApiOperation(value = "选择录用方式")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "studentSign", value = "studentSign", required = true, dataType = "studentSign")
    })
    @PutMapping("/student/sign/pick-dispatch-hired-way")
    public JsonResult pickDispatchHiredWay(@RequestBody StudentSign studentSign) {
        return studentSignService.pickDispatchHiredWay(studentSign, getLoginUserId());
    }

    @PreAuthorize("hasAuthority('student')")
    @OperLog(value = title, desc = "提交毕业去向登记", result = true)
    @ApiOperation(value = "提交毕业去向登记")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "studentSign", value = "studentSign", required = true, dataType = "studentSign")
    })
    @PutMapping("/student/sign/submit")
    public JsonResult submit(@RequestBody StudentSign studentSign) {
        return studentSignService.submit(studentSign, getLoginUserId());
    }

    @PreAuthorize("hasAuthority('student')")
    @OperLog(value = title, desc = "上传协议备案", result = true)
    @ApiOperation(value = "上传协议备案")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "studentSign", value = "studentSign", required = true, dataType = "studentSign")
    })
    @PutMapping("/student/sign/submit-record")
    public JsonResult submitRecord(@RequestBody StudentSign studentSign) {
        return studentSignService.submitRecord(studentSign, getLoginUserId());
    }

    @PreAuthorize("hasAuthority('student')")
    @OperLog(value = title, desc = "查询签约解约解冻期限制")
    @ApiOperation(value = "查询签约解约解冻期限制")
    @GetMapping("/student/sign/termination-frozen-day")
    public JsonResult terminationFrozenDay() {
        return studentSignService.terminationFrozenDay(getLoginUserId());
    }

    @PreAuthorize("hasAuthority('student')")
    @OperLog(value = title, desc = "应约", result = true)
    @ApiOperation(value = "应约")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "studentSign", value = "studentSign", required = true, dataType = "studentSign")
    })
    @PutMapping("/student/sign/agreed")
    public JsonResult agreed(@RequestBody StudentSign studentSign) {
        return studentSignService.agreedSign(studentSign, getLoginUserId());
    }

    @PreAuthorize("hasAuthority('student')")
    @OperLog(value = title, desc = "申请解约", result = true)
    @ApiOperation(value = "申请解约")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "studentSign", value = "studentSign", required = true, dataType = "studentSign")
    })
    @PutMapping("/student/sign/termination")
    public JsonResult termination(@RequestBody StudentSign studentSign) {
        return studentSignService.termination(studentSign, getLoginUserId());
    }

    @PreAuthorize("hasAuthority('student')")
    @OperLog(value = title, desc = "申请改派", result = true)
    @ApiOperation(value = "申请改派")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "studentSign", value = "studentSign", required = true, dataType = "studentSign")
    })
    @PutMapping("/student/sign/dispatch")
    public JsonResult dispatch(@RequestBody StudentSign studentSign) {
        return studentSignService.dispatch(studentSign);
    }

    @PreAuthorize("hasAuthority('student')")
    @OperLog(value = title, desc = "关闭消息提示")
    @ApiOperation(value = "关闭消息提示")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键ID", required = true, dataType = "Integer")
    })
    @PutMapping("/student/sign/close")
    public JsonResult dispatch(Integer id) {
        studentSignService.closeMsg(id);
        return JsonResult.ok();
    }

    @PreAuthorize("hasAuthority('student')")
    @OperLog(value = title, desc = "确认毕业去向")
    @ApiOperation(value = "确认毕业去向")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键ID", required = true, dataType = "Integer")
    })
    @PutMapping("/student/sign/confirm")
    public JsonResult confirm(Integer id) {
        StudentSign studentSign = new StudentSign();
        studentSign.setId(id);
        studentSign.setConfirmState(StudentSignConstants.CONFIRM_TRUE);
        studentSign.setConfirmDate(new Date());
        studentSignService.updateById(studentSign);
        return JsonResult.ok();
    }

    @PreAuthorize("hasAuthority('student')")
    @OperLog(value = title, desc = "决定单位修改协议内容")
    @ApiOperation("决定单位修改协议内容")
    @GetMapping("/student/sign/choice-company-edit")
    public JsonResult choiceCompanyEdit(Integer studentSignEditId, Integer state) {
        return studentSignService.choiceCompanyEdit(studentSignEditId, state, getLoginUserId());
    }

    @PreAuthorize("hasAuthority('student')")
    @ApiOperation("协议就业打印表")
    @ApiPageParam
    @PostMapping("/student/sign/print/deal")
    public JsonResult dealPrint() {
        return studentSignService.dealPrint(null, getLoginUserId());
    }

    @PreAuthorize("hasAuthority('student')")
    @ApiOperation("灵活就业打印表")
    @ApiPageParam
    @PostMapping("/student/sign/print/agile")
    public JsonResult agilePrint() {
        return studentSignService.agilePrint(null, getLoginUserId());
    }

    @PreAuthorize("hasAuthority('student')")
    @ApiOperation("自由职业打印表")
    @ApiPageParam
    @PostMapping("/student/sign/print/free")
    public JsonResult freePrint() {
        return studentSignService.freePrint(null, getLoginUserId());
    }

    @PreAuthorize("hasAuthority('student')")
    @ApiOperation("自主创业打印表")
    @ApiPageParam
    @PostMapping("/student/sign/print/venture")
    public JsonResult venturePrint() {
        return studentSignService.venturePrint(null, getLoginUserId());
    }

}
